import { NextRequest } from 'next/server';
import prisma from '@/lib/prisma';
import { ResponseUtil } from '@/utils/response';

export async function POST(req: NextRequest) {
  try {
    const { nickname, phone } = await req.json();

    if (!nickname && !phone) {
      return ResponseUtil.badRequest('请提供昵称或手机号');
    }

    const result: { nicknameExists?: boolean; phoneExists?: boolean } = {};

    // 检查昵称是否重复
    if (nickname) {
      const existingUser = await prisma.user.findUnique({
        where: { nickname },
        select: { id: true }
      });
      result.nicknameExists = !!existingUser;
    }

    // 检查手机号是否重复
    if (phone) {
      const existingUser = await prisma.user.findUnique({
        where: { phone },
        select: { id: true }
      });
      result.phoneExists = !!existingUser;
    }

    return ResponseUtil.success(result);
  } catch (error) {
    console.error('检查重复失败:', error);
    return ResponseUtil.serverError('检查重复失败');
  }
} 